package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCustomerExcel;
import com.ruoyi.system.service.ISysCustomerExcelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户线索ExcelController
 *
 * @author ruoyi
 * @date 2025-06-15
 */
@RestController
@RequestMapping("/system/excel")
public class SysCustomerExcelController extends BaseController
{
    @Autowired
    private ISysCustomerExcelService sysCustomerExcelService;

    /**
     * 查询客户线索Excel列表
     */
    @PreAuthorize("@ss.hasPermi('system:excel:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCustomerExcel sysCustomerExcel)
    {
        startPage();
        List<SysCustomerExcel> list = sysCustomerExcelService.selectSysCustomerExcelList(sysCustomerExcel);
        return getDataTable(list);
    }

    /**
     * 导出客户线索Excel列表
     */
    @PreAuthorize("@ss.hasPermi('system:excel:export')")
    @Log(title = "客户线索Excel", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCustomerExcel sysCustomerExcel)
    {
        List<SysCustomerExcel> list = sysCustomerExcelService.selectSysCustomerExcelList(sysCustomerExcel);
        ExcelUtil<SysCustomerExcel> util = new ExcelUtil<SysCustomerExcel>(SysCustomerExcel.class);
        util.exportExcel(response, list, "客户线索Excel数据");
    }

    /**
     * 获取客户线索Excel详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:excel:query')")
    @GetMapping(value = "/{grade}")
    public AjaxResult getInfo(@PathVariable("grade") String grade)
    {
        return success(sysCustomerExcelService.selectSysCustomerExcelByGrade(grade));
    }

    /**
     * 新增客户线索Excel
     */
    @PreAuthorize("@ss.hasPermi('system:excel:add')")
    @Log(title = "客户线索Excel", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCustomerExcel sysCustomerExcel)
    {
        return toAjax(sysCustomerExcelService.insertSysCustomerExcel(sysCustomerExcel));
    }

    /**
     * 修改客户线索Excel
     */
    @PreAuthorize("@ss.hasPermi('system:excel:edit')")
    @Log(title = "客户线索Excel", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCustomerExcel sysCustomerExcel)
    {
        return toAjax(sysCustomerExcelService.updateSysCustomerExcel(sysCustomerExcel));
    }

    /**
     * 删除客户线索Excel
     */
    @PreAuthorize("@ss.hasPermi('system:excel:remove')")
    @Log(title = "客户线索Excel", businessType = BusinessType.DELETE)
    @DeleteMapping("/{grades}")
    public AjaxResult remove(@PathVariable String[] grades)
    {
        return toAjax(sysCustomerExcelService.deleteSysCustomerExcelByGrades(grades));
    }
}